package com.jshare.tiezi.use;

import java.sql.Timestamp;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.jshare.dao.MemberDAO;
import com.jshare.dao.TieziDAO;
import com.jshare.entity.Member;
import com.jshare.entity.Tiezi;
import com.jshare.entity.TzReply;

@Service("tieziToUseService")
public class TieziToUseImpl implements TieziToUse {
	@Resource(name="memberDao")
	private MemberDAO memberDao;
	@Resource(name="tieziDao")
	private TieziDAO tieziDao;
	
	public TieziDAO getTieziDao() {
		return tieziDao;
	}

	public void setTieziDao(TieziDAO tieziDao) {
		this.tieziDao = tieziDao;
	}

	public MemberDAO getMemberDao() {
		return memberDao;
	}

	public void setMemberDao(MemberDAO memberDao) {
		this.memberDao = memberDao;
	}

	public Tiezi changetoTiezi(String toppic, String tags, String member_name) {
		Tiezi tie = new Tiezi();
		tie.setTags(tags);
		tie.setToppic(toppic);
		Member member = memberDao.findById(member_name);
		tie.setMember(member);
		tie.setPostdate(new Timestamp(System.currentTimeMillis()));
		tie.setTzReplies(null);
		return tie;
	}

	public TzReply changetoRzReply(Integer tiezi_id, String replyer,
			String content, Integer locate) {
		Tiezi tie = tieziDao.findById(tiezi_id);
		Member member = memberDao.findById(replyer);
		TzReply tr = new TzReply(tie, member, content, locate);
		return tr;
	}

}
